<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    span:hover {
      cursor: pointer;
      text-decoration: underline
    }

    #theme #conter p {
      line-height: 30px;
    }

    #conter {
      border: 1px solid #000;
      overflow: hidden;
      max-height: 0;
    }

    li {
      list-style: none;
    }

    span {
      display: block;
      padding: 10px 10px;
      background-color: #f2f2f2;
      border: 1px solid #ccc;
      border-top-left-radius: 3px;
      border-top-right-radius: 3px;
    }
  </style>
</head>

<body>
  <span>#1.测试内容</span>
  <div id="conter">
    <p>1.内容内容</p>
    <p>1.内容内容</p>
    <p>1.内容内容</p>
  </div>

  <span>#2.测试内容</span>
  <div id="conter">
    <p>2.内容内容</p>
    <p>2.内容内容</p>
    <p>2.内容内容</p>
  </div>

  <span>#3.测试内容</span>
  <div id="conter">
    <p>3.内容内容</p>
    <p>3.内容内容</p>
    <p>3.内容内容</p>
  </div>
  <script>
    var spanTo = document.getElementsByTagName('span');
    console.log('@', spanTo)
    for (var i = 0; i < spanTo.length; i++) {
      //监听事件
      spanTo[i].onclick = function () {
        //返回指定元素之后的下一个兄弟元素
        var brotherTo = this.nextElementSibling;
        //当他等于上面的 span 点击的时候就会为空
        if (brotherTo.style.maxHeight) {
          brotherTo.style.maxHeight = null;
          //当他不等于上面那个 span 点击的时候就他显示 span
        } else {
          //他返回该元素的像素高度，高度包含内边距
          brotherTo.style.maxHeight = brotherTo.scrollHeight + 'px'
        }
      }
    }
  </script>
</body>

</html>